package com.boot.persistence.controller.association;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.boot.persistence.controller.ControllerImpl;
import com.boot.persistence.mapper.IMapper;
import com.boot.persistence.model.AssociationModel;
import com.boot.persistence.model.BaseModel;
import com.boot.persistence.service.association.IAssociationService;
import com.boot.web.http.HttpModel;
import com.boot.web.util.HttpResponseUtil;
import org.springframework.http.ResponseEntity;

import javax.validation.Validator;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description 连接表控制层模板
 * @date 2020/2/24 11:03
 **/
public class AssociationControllerImpl<Tid extends Serializable, Mid extends Serializable, Nid extends Serializable,
        T extends AssociationModel<Tid, Mid, Nid>, M extends BaseModel<Mid>, N extends BaseModel<Nid>,
        Service extends IAssociationService<Tid, Mid, Nid, T, M, N, ? extends IMapper<T>, ? extends BaseMapper<M>, ? extends BaseMapper<N>>
        > extends ControllerImpl<Tid, T, Service>
        implements IAssociationMapping<Mid, Nid, M, N> {

    public AssociationControllerImpl(Service service, Validator validator) {
        super(service, validator);
    }

    @Override
    public ResponseEntity<HttpModel<Collection<N>>> m2n(Mid mid) {
        return HttpResponseUtil.OK("查询成功", service.m2n(mid));
    }

    @Override
    public ResponseEntity<HttpModel<Collection<N>>> m2n(List<Mid> mids) {
        return HttpResponseUtil.OK("查询成功", service.m2n(mids));
    }

    @Override
    public ResponseEntity<HttpModel<Collection<M>>> n2m(Nid nid) {
        return HttpResponseUtil.OK("查询成功", service.n2m(nid));
    }

    @Override
    public ResponseEntity<HttpModel<Collection<M>>> n2m(List<Nid> nids) {
        return HttpResponseUtil.OK("查询成功", service.n2m(nids));
    }
}
